/**
 * 格式化文件大小
 * @param {number} bytes - 文件大小（字节）
 * @returns {string} 格式化后的大小字符串
 */
export const formatFileSize = (bytes) => {
    if (bytes === undefined || bytes === null) return '0 B'
    if (bytes < 1024) return `${bytes} B`
    if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`
    if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(2)} MB`
    return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`
  }
  
  /**
   * 获取字典标签
   * @param {Array} options - 字典选项数组
   * @param {string|number} value - 字典值
   * @returns {string} 字典标签
   */
  export const getDictLabel = (options, value) => {
    if (!options || !options.length || value === undefined || value === null) return ''
    const item = options.find(option => option.dictValue === value || option.value === value)
    return item ? item.dictLabel || item.label : ''
  }
  
  /**
   * 根据扩展名获取文件类型
   * @param {string} ext - 文件扩展名
   * @returns {string} MIME类型
   */
  export const getFileTypeByExt = (ext) => {
    if (!ext) return 'application/octet-stream'
    const typeMap = {
      png: 'image/png',
      jpg: 'image/jpeg',
      jpeg: 'image/jpeg',
      gif: 'image/gif',
      bmp: 'image/bmp',
      webp: 'image/webp',
      pdf: 'application/pdf',
      zip: 'application/zip',
      rar: 'application/x-rar-compressed',
      "7z": 'application/x-7z-compressed',
      mp4: 'video/mp4',
      avi: 'video/x-msvideo',
      mov: 'video/quicktime',
      xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      xls: 'application/vnd.ms-excel',
      docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      doc: 'application/msword',
      pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
      ppt: 'application/vnd.ms-powerpoint',
      txt: 'text/plain',
      csv: 'text/csv',
      json: 'application/json'
    }
    return typeMap[ext.toLowerCase()] || 'application/octet-stream'
  }